package main

import (
	"database/sql"
	"errors"
	"fmt"
	"log"

	_ "github.com/go-sql-driver/mysql"
)

func TestErrWrap(a int) (string, error) {
	db, err := sql.Open("mysql",
		"dog:123456@tcp(localhost:3306)/my_db")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	var (
		name string
	)
	err = db.QueryRow("select name from users where id = ?", a).Scan(&name)
	if err != nil {
		fmt.Println("query error")
		if err == sql.ErrNoRows {
			return "", fmt.Errorf("%w, data is nil", err)
		}
		log.Fatal(err)
	}

	return "", err
}

func main() {
	_, err := TestErrWrap(71)
	err = errors.Unwrap(err)
	if errors.Is(err, sql.ErrNoRows) {
		fmt.Println("hello world")
	}
}
